﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yandex.XML.Search;

namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
           
            Console.WriteLine("Enter your yandex query:");
            string query = Console.ReadLine();
            // Your Yandex Credentials (http://xml.yandex.ru/settings.xml);
             Yandex.XML.Search.APICredentials _DefaultCredential = new APICredentials();
             Console.WriteLine("You IP should be set on Yandex.XML Profile (http://xml.yandex.ru/settings.xml)");
             Console.WriteLine("Yandex.xml User:");
             _DefaultCredential.User = Console.ReadLine();
             Console.WriteLine("Yandex.xml Key:");
             _DefaultCredential.Key = Console.ReadLine();


            YandexRegion _region = YandexRegion.GetList().FirstOrDefault(n => n.StringName.Contains("Москва"));
            
            YandexSearchQuery _query = new YandexSearchQuery(query, _DefaultCredential,_region,RequestMethodEnum.POST);
            Console.WriteLine("Region to search is: " + _region.StringName);
            List<YaSearchResult> resultList = _query.GetResponseToList();

            foreach (YaSearchResult res in resultList.Take(50))
            {
               Console.WriteLine();
               Console.WriteLine("    " + res.Position + " " + res.Title);
               Console.WriteLine(res.Description);
               Console.WriteLine("              " + res.DisplayUrl);
               Console.WriteLine();
            
            }
           
         




        }
    }
}
